﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Xml;
using UmcProvider.Controls;
using System.ComponentModel.Design.Serialization;
using UmcProvider.Properties;

namespace UmcProvider
{
    public sealed class UmcHost : System.Windows.Forms.UserControl
    {
        private Body body;


        private Point bodyLocation = new Point(24, 55);
        private Size hostSize = new Size(256, 499);
        private Size bodySize = new Size(207, 346);

        public void InitializeDesigner(IDesignerLoaderHost host)
        {
            this.Size = hostSize;
            this.BackgroundImage = Resources.SmartPhone;
            this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;

            body = (Body)host.CreateComponent(typeof(Body), "Body");
            body.Location = bodyLocation;
            body.Size = bodySize;
            body.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            this.Controls.Add(body);

            this.SizeChanged += new EventHandler(UmcHost_SizeChanged);
        }

        void UmcHost_SizeChanged(object sender, EventArgs e)
        {
            float deltaX = this.Size.Width / (float)hostSize.Width;
            float deltaY = this.Size.Height / (float)hostSize.Height;

            float delta = deltaX > deltaY ? deltaX : deltaY;

            body.Location = new Point((int)(bodyLocation.X * delta), (int)(bodyLocation.Y * delta));
            body.Size = new Size((int)(bodySize.Width * delta), (int)(bodySize.Height * delta));
            this.Size = new Size((int)(hostSize.Width * delta), (int)(hostSize.Height * delta));
        }

        public System.Windows.Forms.Control Body
        {
            get { return body; }
        }
    }


    [Designer(typeof(UmcContainerDesigner<IBody>))]
    public sealed class Body : System.Windows.Forms.Panel, IBody
    {
    }

    public interface IBody : IUmc
    {
        bool Enabled { get; }
        //bool Visible { get; }
        string Text { get; }
        Color BackColor { get; }
        Font Font { get; }
        Color ForeColor { get; }
        //
        bool AutoScroll { get; }
        Image BackgroundImage { get; }
    }

    public sealed class UmcBody : DefaultConverter<UmcBody, Body>, IBody
    {
        //BUG:!@#!@#
        //public override IComponent DeSerialize(IDesignerHost host, XmlDocument document, XmlNode[] node)
        //{
        //    IComponent root = base.DeSerialize(host, document, node);

        //    foreach (var p in properties)
        //    {
        //        host.RootComponent.GetType().GetProperty(p).SetValue(
        //            host.RootComponent,
        //            root.GetType().GetProperty(p).GetValue(root, null),
        //            null);
        //    }

        //    return root;
        //}


        #region IBody Members

        public bool AutoScroll
        {
            get { throw new NotImplementedException(); }
        }

        public Image BackgroundImage
        {
            get { throw new NotImplementedException(); }
        }

        #endregion

        #region IControl Members

        public bool Enabled
        {
            get { throw new NotImplementedException(); }
        }

        public Size Size
        {
            get { throw new NotImplementedException(); }
        }

        public Point Location
        {
            get { throw new NotImplementedException(); }
        }

        public string Text
        {
            get { throw new NotImplementedException(); }
        }

        public Color BackColor
        {
            get { throw new NotImplementedException(); }
        }

        public Font Font
        {
            get { throw new NotImplementedException(); }
        }

        public Color ForeColor
        {
            get { throw new NotImplementedException(); }
        }

        #endregion

        #region IUmc Members

        public string Name
        {
            get { throw new NotImplementedException(); }
        }

        #endregion
    }
}


